package socketmvc.core.packets;

import socketmvc.core.packets.basic.JsonBasicPacket;
import socketmvc.core.packets.basic.impl.JsonBinPacket;
import socketmvc.core.packets.basic.impl.JsonGzipPacket;
import socketmvc.core.packets.basic.impl.JsonTextBody;
import socketmvc.core.packets.basic.impl.JsonSimplePacket;
import socketmvc.core.packets.biz.SockFile;
import socketmvc.core.packets.biz.SockMultiFile;

import java.io.File;
import java.util.Arrays;
import java.util.List;

public class PacketStaticFactory {

    private static JsonTextBody createTextBody(String cmd, Object param){
        JsonTextBody textBody = new JsonTextBody();
        textBody.setBody(param);
        textBody.setCommand(cmd);
        return textBody;
    }

    private static JsonTextBody createTextBody(Object param){
        return createTextBody(null,param);
    }

    public static JsonBasicPacket createGzipPacket(Object param){
        return new JsonGzipPacket(createTextBody(param));
    }

    public static JsonBasicPacket createGzipPacket(String cmd,Object param){
        return new JsonGzipPacket(createTextBody(cmd,param));
    }

    public static JsonBasicPacket createSimplePacket(Object param){
        return new JsonSimplePacket(createTextBody(param));
    }

    public static JsonBasicPacket createSimplePacket(String cmd,Object param){
        return new JsonSimplePacket(createTextBody(cmd,param));
    }

    public static JsonBasicPacket createBinPacket(Object param, byte[] binBody){
        return new JsonBinPacket(createTextBody(param),binBody);
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, byte[] binBody){
        return new JsonBinPacket(createTextBody(cmd,param),binBody);
    }

    public static JsonBasicPacket createBinPacket(Object param, File binBody) {
        return createBinPacket(param,new SockFile(binBody));
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, File binBody) {
        return createBinPacket(cmd,param,new SockFile(binBody));
    }

    public static JsonBasicPacket createBinPacket(Object param, SockFile binBody) {
        return new JsonBinPacket(createTextBody(param),binBody);
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, SockFile binBody) {
        return new JsonBinPacket(createTextBody(cmd,param),binBody);
    }

    public static JsonBasicPacket createBinPacket(Object param, SockMultiFile binBody) {
        return new JsonBinPacket(createTextBody(param),binBody);
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, SockMultiFile binBody) {
        return new JsonBinPacket(createTextBody(cmd,param),binBody);
    }

    public static JsonBasicPacket createBinPacket(Object param, List<SockFile> binBody) {
        return createBinPacket(param,new SockMultiFile(binBody));
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, List<SockFile> binBody) {
        return createBinPacket(cmd,param,new SockMultiFile(binBody));
    }

    public static JsonBasicPacket createBinPacket(Object param, File[] binBody) {
        return createBinPacket(null,param,binBody);
    }

    public static JsonBasicPacket createBinPacket(String cmd,Object param, File[] binBody) {
        List<SockFile> list = Arrays.stream(binBody).map(SockFile::new).toList();
        return createBinPacket(cmd,param,list);
    }

}
